Color OLED module library  v0.5
Library for the WaveShare 0.96-inch color OLED (SSD1331) module
ssd1331_drawLine.c
1 /*
2  * @file ssd1331_drawLine.c
3  *
4  * @author Matthew Matz
5  *
6  * @version 0.9
7  *
8  * @copyright Copyright (C) Parallax, Inc. 2019. See end of file for
9  * terms of use (MIT License).
10  *
11  * @brief 0.96-inch RGB OLED display bitmap driver, see ssd1331_h. for documentation.
12  *
13  * @detail Please submit bug reports, suggestions, and improvements to
14  * this code to editor@parallax.com.
15  */
16 
17 
18 #include "ssd1331.h"
19 
20 
21 void ssd1331_drawLine(screen_t* dev, int x0, int y0, int x1, int y1, int color) {
22  int mask_cs = (1 << dev->dev_id);
23  int mask_sdi = (1 << dev->sdi_pin);
24  int mask_clk = (1 << dev->clk_pin);
25  int mask_dc = (1 << dev->dc_pin);
26 
27  ssd1331_writeLockSet(dev->dev_id);
28 
29  ssd1331_writeByte(mask_cs, mask_sdi, mask_clk, mask_dc, SSD1331_CMD_DRAWLINE, 0);
30  ssd1331_writeByte(mask_cs, mask_sdi, mask_clk, mask_dc, x0, 0);
31  ssd1331_writeByte(mask_cs, mask_sdi, mask_clk, mask_dc, y0, 0);
32  ssd1331_writeByte(mask_cs, mask_sdi, mask_clk, mask_dc, x1, 0);
33  ssd1331_writeByte(mask_cs, mask_sdi, mask_clk, mask_dc, y1, 0);
34 
35  ssd1331_writeByte(mask_cs, mask_sdi, mask_clk, mask_dc, (color >> 11) << 1, 0);
36  ssd1331_writeByte(mask_cs, mask_sdi, mask_clk, mask_dc, (color >> 5) & 0x3F, 0);
37  ssd1331_writeByte(mask_cs, mask_sdi, mask_clk, mask_dc, (color << 1) & 0x3F, 0);
38 
39  //TODO: is this needed?
40  int _tMark = CNT + (CLKFREQ / 100000);
41  while (_tMark > CNT); // Wait for system clock target
42 
43  ssd1331_writeLockClear(dev->dev_id);
44 }
45 
46 void ssd1331_drawFastVLine(screen_t* dev, int x, int y, int w, int color) {
47  ssd1331_drawLine(dev, x, y, x, y + w - 1, color);
48 }
49 
50 void ssd1331_drawFastHLine(screen_t* dev, int x, int y, int h, int color) {
51  ssd1331_drawLine(dev, x, y, x + h - 1, y, color);
52 }
53 
54 
55